let arr = ['a', 'b', 'a']

let result = arr.reduce((obj, key) => {
    obj[key] = obj[key] === undefined ? 1 : obj[key] + 1;
    return obj;
}, {});

console.log(result)
